/* hal_ipc.c */
#include "hal_ipc.h"

void IPC_ResetPeriph(IPC_Type * base, IPC_Periph_Type periph)
{
    /* assert the reset. */
    base->CTRL[periph] |= IPC_CTRL_SWREN_MASK;
    
    /* de-assert the reset. */
    base->CTRL[periph] &= ~IPC_CTRL_SWREN_MASK;
}

#if 0
void IPC_SetPeriphClockConf(IPC_Type * base, IPC_Periph_Type periph, IPC_PeriphFunClk_Type * src)
{
    /* disable the clock source before any settings. */
    base->CTRL[periph] = 0u;

    if (src) /* not null. */
    {
        /* setup the div with clock source disabled. */
        base->CTRL[periph] = IPC_CTRL_DIV(src->Div);
        
        /* setup the clock source later. */
        base->CTRL[periph] = IPC_CTRL_CLKEN_MASK | IPC_CTRL_SRCSEL(src->Source) | IPC_CTRL_DIV(src->Div);
    }
}
#endif

void IPC_EnablePeriph(IPC_Type * base, IPC_Periph_Type periph , IPC_PeriphFunClkSrc_Type src, IPC_PeriphFunClkDiv_Type div)
{
    /* disable the clock source before any settings. */
    base->CTRL[periph] = 0u;
    
    /* setup the div with clock source disabled. */
    base->CTRL[periph] = IPC_CTRL_DIV(div);
        
    /* setup the clock source later. */
    base->CTRL[periph] = IPC_CTRL_CLKEN_MASK | IPC_CTRL_SRCSEL(src) | IPC_CTRL_DIV(div);
}

/* EOF. */

